package com.itheima.service;

import com.itheima.dao.ManagerDao;
import com.itheima.domain.Fruit;
import com.itheima.domain.User;

import java.io.IOException;
import java.util.List;
import java.util.TreeSet;

public class ManagerService {

    private ManagerDao managerDao = new ManagerDao();
    //判断水果id是否已经存在方法
    public boolean isIdExists(String id) {
        boolean flag = false;
        try {
            flag = managerDao.isIdExists(id);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return flag;
    }

    //判断水果名称是否已经存在方法
    public boolean isNameExists(String newName) {
        boolean flag = false;
        try {
            flag = managerDao.isNameExists(newName);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return flag;
    }

    //上架水果方法
    public void addFruit(Fruit fruit) {
        try {
            managerDao.addFruit(fruit);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    //获取已上架的水果列表
    public TreeSet<Fruit> getFruitSet() {
        TreeSet<Fruit> fruitSet = null;
        try {
            fruitSet = managerDao.getFruitSet();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return fruitSet;
    }

    //删除水果方法
    public void deleteFruit(String dleId){
        try {
            managerDao.deleteFruit(dleId);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    //修改水果方法
    public void updateFruit(Fruit fruit) {
        try {
            managerDao.updateFruit(fruit);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }



    public boolean addUser(User user) {
        return managerDao.addUser(user);
    }

    public boolean isExists(String id) {
        return managerDao.isExists(id);
    }

    public User selectById(String id) {
        return managerDao.selectById(id);
    }

    public boolean updateUserName(String id, String name) {
        return managerDao.updateUserName(id,name);
    }

    public void charGing(String id, double money) {
        managerDao.charGing(id,money);
    }

    public List<User> selectAll() {
        return managerDao.selectAll();
    }

    public void deleteUser(String id) {
        managerDao.deleteUser(id);
    }

    public void pointsExchange(String id, int i) {
       managerDao.pointsExchange(id, i);
    }
}
